package two.chapter_1.c1_4;

import edu.princeton.cs.algs4.Point2D;
import edu.princeton.cs.algs4.StdDraw;
import edu.princeton.cs.algs4.StdOut;
import edu.princeton.cs.algs4.StdRandom;

public class DrawDoublingTest {

    public static double timeTrial(int N){
        int MAX=1000000;
        int []a=new int[N];
        for (int i=0;i<N;i++){
            a[i]=StdRandom.uniform(-MAX,MAX);
        }
        Stopwatch timer=new Stopwatch();
        int cnt=TwoSum.twoSum(a);
        return timer.elapseTime();
    }

    public static void main(String[]args){
        StdDraw.setPenRadius(0.005);
        StdDraw.setPenColor(StdDraw.DARK_GRAY);
        two.chapter_1.c1_2.Point2D [] point2DS=new two.chapter_1.c1_2.Point2D[12];
        int i=0;
        for (int N=250;i<12;N+=N){

            double time=timeTrial(N);
            StdOut.println( String.format("%7d %5.1f\n",N,time));
            //Point2D point2D=new Point2D(N,time);
            point2DS[i]=new two.chapter_1.c1_2.Point2D(N,time);
            i++;
        }

        double x=point2DS[11].x();
        double y=point2DS[11].y();
        StdDraw.setXscale(0,x);
        StdDraw.setYscale(0,y);
        for (int j=0;j<12;j++){
            StdDraw.point(point2DS[j].x(),point2DS[j].y());
        }

        for (int j=0;j<12;j++){
            StdDraw.point(point2DS[j].x(),Math.log(point2DS[j].y()));
        }
    }
}
